package www.qiyue.pt;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import www.qiyue.utils.JsonUtilz;
import www.qiyue.utils.UUIDGenerator;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class House {
    @Autowired
    private JdbcTemplate jdbcTemplate;



    @RequestMapping("house")
    public  String getHouse(){
        int i=923456;
        String house_li="select column_name from information_schema.columns where table_schema='reis' and table_name='reis_contract'";
        //String house_1="SELECT * from ais_house WHERE id like '2020324%'";
        List<Map<String, Object>> mapList = jdbcTemplate.queryForList(house_li);
        //List<Map<String, Object>> mapList1 = jdbcTemplate.queryForList(house_li);
        List<Map<String,String>>list=new ArrayList<>();
        for (Map<String, Object> map : mapList) {
            HashMap<String, String> Hash = new HashMap<>();
            String key = map.get("column_name").toString();
            Hash.put("from",key);
            Hash.put("to",key);
            list.add(Hash);
        }
        String s = JsonUtilz.toString(list, true);
        System.out.println("s = " + s);
        return "好了";

    }

    private String getsql(List<Map<String, Object>> mapsL,Map<String, Object> maps){
        StringBuilder sb = new StringBuilder();
        StringBuilder ve = new StringBuilder();
        int a=0;
        for (Map<String, Object> map : mapsL) {
            a++;
            sb.append("INSERT INTO `ais_pt`.`ais_house`(");
            ve.append(" VALUES (");
            String key = map.get("column_name").toString();
            if (a==mapsL.size()) {
                sb.append(" " + key + ")");
                if (key.equals("id")) {
                    String id = UUIDGenerator.generate();
                    ve.append(id + ")");
                } else {
                    ve.append(maps.get(key)+")");
                }
            }else {
                sb.append(" " + key + ",");
                if (key.equals("id")) {
                    String id = UUIDGenerator.generate();
                    ve.append(id + ",");
                } else {
                    ve.append(maps.get(key)+",");
                }
            }
        }
        System.out.println(sb+""+ve);
        return null;
    }
}
